home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / croutes.zip / GETTIME.C < prev    next >
Text File  |  1984-05-17  |  2KB  |  51 lines

  1. /*                            *** gettime.c ***                      */
  2. /*                                                                   */
  3. /* IBM-PC microsoft "C" under PC-DOS                                 */
  4. /*                                                                   */
  5. /* Function to return a string containing the time in the format     */
  6. /* HH:MM:SS (military time).                                         */
  7. /*                                                                   */
  8. /* Written by L. Cuthbertson, May 1984                               */
  9. /*                                                                   */
  10. /*********************************************************************/
  11. /*                                                                   */
  12.  
  13. #define NULL    '\000'
  14. #define DELIM   ':'
  15.  
  16. int gettime(string)
  17. char string[];
  18. {
  19.     char hours[3],minutes[3],seconds[3];
  20.     int ih,im,is,iths;
  21.     int i,j;
  22.  
  23.     /* call assembler routine to get time in integer format */
  24.     dostime(&ih,&im,&is,&iths);
  25.  
  26.     /* convert integers to strings - ignore 1/100ths of second */
  27.     sprintf(hours,"%02d",ih);
  28.     sprintf(minutes,"%02d",im);
  29.     sprintf(seconds,"%02d",is);
  30.  
  31.     /* build output string */
  32.     j = 0;
  33.     for(i=0;hours[i] != NULL;i++)
  34.         string[j++] = hours[i];
  35.  
  36.     string[j++] = DELIM;
  37.  
  38.     for(i=0;minutes[i] != NULL;i++)
  39.         string[j++] = minutes[i];
  40.  
  41.     string[j++] = DELIM;
  42.  
  43.     for(i=0;seconds[i] != NULL;i++)
  44.         string[j++] = seconds[i];
  45.  
  46.     string[j] = NULL;
  47.  
  48.     /* done */
  49.     return(0);
  50. }
  51.